<?php require admin_tpl('header')?>

<div class="tab">
	<ul>
		<li><a href="?mod=data&ac=recache"<?php echo $tabon['recache']?>>刷新缓存</a></li>
		<li><a href="?mod=data&ac=recalendar"<?php echo $tabon['recalendar']?>>重建日历</a></li>
		<li><a href="?mod=data&ac=dbop"<?php echo $tabon['dbop']?>>数据表维护</a></li>
		<li><a href="?mod=data&ac=export"<?php echo $tabon['export']?>>数据导出</a></li>
		<li><a href="?mod=data&ac=baklist"<?php echo $tabon['baklist']?>>数据导入</a></li>
	</ul>
</div>

<div class="main">

	<table width="100%" cellspacing="0">
	<tr><td>

	<?php if ($ac=='recache') { ?>
	<table>
		<tr>
			<td>某些系统设置需要刷新缓存才能生效。</td>
		</tr>
		<tr>
			<td>
			<input type="button" onclick="window.location='?mod=data&ac=recache&do=recache'" value="  刷新系统缓存  " class="button" />
			<input type="button" onclick="window.location='?mod=data&ac=recache&do=clearcachepage'" value="  清空缓存页面  " class="button" />
			</td>
		</tr>
	</table>
	<?php } elseif ($ac=='recalendar') { ?>
	<table>
		<tr>
			<td>当日历归档显示不正确时，你可以重建日历修复。在文章量大的情况下，可能需要花费较长时间，请耐心等待。</td>
		</tr>
		<tr>
			<td><input type="button" onclick="window.location='?mod=data&ac=recalendar&do=exec'" value=" 重建日历  " class="button" /></td>
		</tr>
	</table>
	<?php } elseif ($ac=='dbop') { ?>
	<form name="form1" method="post" action="?mod=data&ac=dbop">
	<input type="hidden" value="yes" name="dosubmit" />
	<table cellspacing="0" class="datalist" width="100%" id="list">
		<tr>
			<th width="50" class="firstcol">选择</th>
			<th>表名</th>
			<th>表用途</th>
			<th width="120">类型</th>
			<th width="120">记录数</th>
			<th width="120">数据</th>
			<th width="120">索引</th>
			<th width="120">碎片</th>
			<th width="120">总大小</th>
		</tr>
		<?php foreach ( $tables as $table ) { ?>
		<tr align="center">
			<td><input type="checkbox" name="id[]" id="db_<?php echo $table['name']?>" class="checkbox" value="<?php echo $table['name']?>" /></td>
			<td align="left"><label for="db_<?php echo $table['name']?>"><?php echo $table['name']?></label></td>
			<td align="left"><?php echo $table['use']?></td>
			<td><?php echo $table['engine']?></td>
			<td><?php echo $table['rows']?></td>
			<td><?php echo $table['data_length']?></td>
			<td><?php echo $table['index_length']?></td>
			<td><?php echo $table['data_free']?></td>
			<td><?php echo $table['size']?></td>
		</tr>
		<?php } ?>
		<tr>
			<td align="center"><input type="checkbox" name="chkall" id="chkall" value="1" class="checkbox" onclick="check_all(this)" /></td>
			<td colspan="10"><label for="chkall">全选</label>
			<input type="radio" name="do" value="repair" id="op_repair" class="radio" checked="checked" /><label for="op_repair"><?php echo __("修复表")?></label>
			<input type="radio" name="do" value="optimize" id="op_optimize" class="radio" /><label for="op_optimize"><?php echo __("优化表")?></label>
			<input type="submit" value="  执 行  " class="submit" />
			(数据库总大小：<?php echo $total_size;?>)
			</td>
		</tr>
	</table>
	</form>
	<?php } elseif ($ac=='export') { ?>
	<form name="backup" method="get" target="do_export" action="admin.php">
	<input type="hidden" name="mod" value="data" />
	<input type="hidden" name="ac" value="export" />
	<input type="hidden" value="yes" name="dosubmit" />
	<table cellspacing="0" class="datalist" width="100%" id="list">
		<tr>
			<th width="50" class="firstcol">选择</th>
			<th width="250">表名</th>
			<th width="250">表用途</th>
			<th width="120">记录数</th>
			<th width="120">大小</th>
			<th>&nbsp;</th>
		</tr>
		<tbody>
		<?php foreach ( $tables as $table ) { ?>
		<tr align="center">
			<td><input type="checkbox" name="id[]" id="db_<?php echo $table['name']?>" class="checkbox" value="<?php echo $table['name']?>" /></td>
			<td align="left"><label for="db_<?php echo $table['name']?>"><?php echo $table['name']?></label></td>
			<td align="left"><?php echo $table['use']?></td>
			<td><?php echo $table['rows']?></td>
			<td><?php echo $table['size']?></td>
			<td>&nbsp;</td>
		</tr>
		<?php } ?>

		<tr>
			<td align="center"><input type="checkbox" name="chkall" value="1" id="chkall" class="checkbox" onclick="check_all(this)" /></td>
			<td colspan="5"><label for="chkall">全选</label></td>
		</tr>
		<tr><td colspan="6" style="background:#EDF0F6;">导出选项：</td></tr>
		<tr>
			<td colspan="6">导出类型：
				<input type="radio" name="type" value="sql" id="type_sql" checked="checked" /><label for="type_sql">SQL</label> 
				<input type="radio" name="type" value="xml" id="type_xml" /><label for="type_xml">XML</label>
			</td>
		</tr>
		<tr>
			<td colspan="6">分卷大小：<input type="text" name="sizelimit" size="5" value="2048" /> K </td>
		</tr>
		<tr>
			<td colspan="6" align="center">
			<input type="submit" class="button" value="开始导出" />
			</td>
		</tr>
		</form>
		</tbody>
		<tbody>
		<tr><td colspan="6" style="background:#EDF0F6;">导出状态</td></tr>
		<tr>
			<td height="100" colspan="6">
			<iframe name="do_export" frameborder="0" id="do_export" width="100%" height="100%"></iframe>
			</td>
		</tr>
		</tbody>
	</table>

	<?php } elseif ($ac=='baklist') { ?>
	<form name="del" method="post" action="?mod=data&ac=bakdel">
		<table cellspacing="0" class="datalist" width="100%" id="list">
			<tr>
				<th width="50" class="firstcol">选择</th>
				<th width="300">目录</th>
				<th width="150">版本</th>
				<th width="200">备份时间</th>
				<th width="80">备份类型</th>
				<th width="120">操作</th>
				<th>&nbsp;</th>
			</tr>
			<?php
			if ( !empty($result) ) {
				foreach ( $result as $row ) {
			?>
			<tr align="center" id="a_<?php echo $row['dir'];?>">
				<td><input type="checkbox" class="checkbox" name="id[]" value="<?php echo $row['dir'];?>" /></td>
				<td align="left"><?php echo $row['path'];?></td>
				<td><?php echo $row['version'];?></td>
				<td><?php echo $row['time'];?></td>
				<td><?php echo $row['type'];?></td>
				<td><a href="?mod=data&ac=import&bakdir=<?php echo $row['dir'];?>">导入</a></td>
				<td>&nbsp;</td>
			</tr>
			<?php
				}
			?>
			<tr>
				<td align="center"><input type="checkbox" class="checkbox" name="chkall" onclick="check_all(this)" id="chkall" /></td>
				<td colspan="6"><label for="chkall">全选</label> <input type="submit" value="删除" onclick="return confirm('一旦删除将不可恢复，确定要删除吗？');" class="submit" /></td>
			</tr>
			<?php
			} else {
				echo '<tr><td colspan="7">没有备份记录...</td></tr>';
			}
			?>
		</table>		
	</form>
 
	<br /> 
	
	<form name="save" method="post" action="?mod=data&ac=import_file" enctype="multipart/form-data"> 
	<table class="sub panel" cellspacing="0"> 
		<tr> 
			<th colspan="2" class="title">从文件导入数据</th> 
		</tr> 
		<tr> 
			<td colspan="2"> 
			<span>导入由JBlog导出的XML等数据文件（文件最大允许<?php echo ini_get('upload_max_filesize'); ?>）。</span> 
			</td> 
		</tr> 
		<tr> 
			<td><input type="file" name="attach[]" /> </td> 
		</tr> 
		<tr>
			<td>类型：<input type="radio" class="radio" name="type" id="type_xml" value="xml" checked="checked" /><label for="type_xml">XML</label></td>
		</tr>
		<tr>
			<td><input type="submit" value=" 上传并导入 " class="submit" /> </td>
		</tr>
	</table> 
	</form>
	<?php } elseif ($ac=='import') { ?>
	<table cellspacing="0" class="datalist" width="100%">
		<tr>
			<th class="firstcol" colspan="2" style="text-align:left;">备份详情</th>
		</tr>
		<tr>
			<td align="right">备份目录：</td><td><?php echo $result['dir'];?></td>
		</tr>
		<tr>
			<td align="right">JBlog版本：</td><td><?php echo $result['version'];?><?php if ( $result['version'] != JBLOG_VERSION ) { echo ' <span style="color:red">（备份数据版本与当前版本不一致，可能会因不兼容而导致数据损坏，请确认无兼容问题再导入。）<span>';}?></td>
		</tr>
		<tr>
			<td align="right">备份时间：</td><td><?php echo $result['time'];?></td>
		</tr>
		<tr>
			<td align="right">备份类型：</td><td><?php echo $result['type'];?></td>
		</tr>
		<tr>
			<td align="right">分卷数目：</td><td><?php echo $result['volume'];?> 卷</td>
		</tr>
		<tr>
			<td></td>
			<td>
			<form name="bakin" method="get" target="do_bakin" action="admin.php">
			<input type="hidden" name="mod" value="data" />
			<input type="hidden" name="ac" value="import" />
			<input type="hidden" name="dosubmit" value="yes" />
			<input type="hidden" name="bakdir" value="<?php echo $bakdir;?>" />
			<input type="hidden" name="filepre" value="<?php echo $result['filepre'];?>" />
			<input type="hidden" name="count" value="<?php echo $result['volume'];?>" />
			<input type="hidden" name="type" value="<?php echo $result['type'];?>" />
			<input type="submit" class="button" value="开始导入" />
			<input type="button" class="button" value="取消返回" onclick="window.location='?mod=data&ac=baklist'" />
			</form>
			</td>
		</tr>
		<tr><td colspan="2" style="background:#EDF0F6;">还原状态</td></tr>
		<tr>
			<td height="100" colspan="2">
			<iframe name="do_bakin" frameborder="0" id="do_bakin" width="100%" height="100%"></iframe>
			</td>
		</tr>
	</table>
	<?php } ?>
	</td></tr>
	</table>

</div>

<?php require admin_tpl('footer')?>